using System.IO;
using System.Net;
namespace MingleReport.HttpRequests
{
    public class MingleHttpAuthenticationRequest : AbstractMingleHttpRequest
    {
        private readonly string username;
        private readonly string password;

        public MingleHttpAuthenticationRequest(string server, string username, string password)
            :base(server)
        {
            this.username = username;
            this.password = password;
        }

        public override string PostString
        {
            get { return "user[login]=" + username + "&user[password]=" + password; }
        }

        public override void Create()
        {
            httpRequest = (HttpWebRequest) WebRequest.Create(server + "/profile/login");
            httpRequest.Method = "POST";
            httpRequest.CookieContainer = new CookieContainer();
            using (Stream stream = httpRequest.GetRequestStream())
            {
                byte[] buffer = ENCODING.GetBytes(PostString);
                stream.Write(buffer, 0, buffer.Length);
            }
        }

        public CookieContainer CookieContainer
        {
            get { return httpRequest.CookieContainer; }
        }

    }
}